package com.greenova.theprojector.biz.services;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.greenova.theprojector.biz.entities.Employee;
import com.greenova.theprojector.biz.entities.repository.EmployeeRepository;

@Service
public class EmployeeService {
	private static final Logger logger = LoggerFactory.getLogger(EmployeeService.class);
	
	@Autowired
	private EmployeeRepository employeeRepository;
	
	public List<Employee> findAll(){
		return employeeRepository.findAll();
	}
	
	public List<Employee> findAllUnassigned(){
		return employeeRepository.findAllUnassigned();
	}
	
	public void assign(Employee employee){
		logger.debug("Assigning Employee Id:" + employee.getEmployeeId());
		Employee dummy = employeeRepository.findUnassignedById(employee.getEmployeeId());
		logger.debug("Fetched Employee:" + dummy);
		
		employeeRepository.addAssigned(dummy);
		employeeRepository.removeUnassigned(employee);
	}
	
	public void unassign(Employee employee){
		logger.debug("Unassigning Employee Id:" + employee.getEmployeeId());
		Employee dummy = employeeRepository.findAssignedById(employee.getEmployeeId());
		logger.debug("Fetched Employee:" + dummy);
		
		employeeRepository.addUnassigned(dummy);
		employeeRepository.removeAssigned(employee);
	}
}
